# -*- coding:utf-8 -*-
from PIL import Image,ImageDraw,ImageFont
import time 

class DrawSomething(object):
    def __init__(self,filepath,fontsize,color):
        self.im = Image.open(filepath)
	font = 'datareport/1.ttf'
	#font = '1.ttf'
	self.size = fontsize
	self.color= color
        self.font = ImageFont.truetype(font,self.size)
        self.draw = ImageDraw.Draw(self.im)
	#self.title = 'you are so good!'
	#self.title = u'你真棒!\n这恩德太棒\n好棒！'


        print '1____'
    def DrawFont(self,info):
	#title = u'你真棒!\n这恩德太棒\n好棒！'
	
        for row in info:
                
            self.draw.text((row["xPosition"],row["yPosition"]),row["title"],self.color,font=self.font)
        #self.draw.text((10,80), RandomChar().GB2312(),(255,255,0),font=self.font)
        #self.draw.text((10,80), RandomChar().GB2312(),(255,255,0),font=self.font)
	#newimg=self.im.rotate(90)
        #newimg.save('2.png')
	m_time_f = "{}.png".format(int(time.time()))
	mediaUrl = 'media/makepic/'+m_time_f
        self.im.save(mediaUrl)
        return mediaUrl

    def DrawFont1(self,info):
        print self.im.size
        print dir(self.im.size)

        #self.draw.text((self.im.size[0]/2,self.im.size[1]/2), u'测试',(255,255,0),font=self.font)
        self.draw.text((222,265), u'测试',(255,255,0),font=self.font)
        self.im.save('2.png')

    def transform_font(self):
        for i,a  in  enumerate(self.title):
            self.draw.text((10,10+i*self.size),a,(255,255,0),font=self.font)
        self.im.save('2.png')



if __name__ == "__main__":
    imh = DrawSomething("t1.png",25,(22,22,22))

    print imh.DrawFont1('ddd')

    #imh.transform_font()
